// ActionScript file
	private var downloadfileRef:FileReference = new FileReference();
	
	private function downloadFile():void
	{
		downloadfileRef.addEventListener(Event.COMPLETE, downloadCompleteHandler);
		downloadfileRef.addEventListener(ProgressEvent.PROGRESS, downloadProgressHandler);
		downloadfileRef.addEventListener(IOErrorEvent.IO_ERROR, downloadIOHandler);

	    var downloadURL:URLRequest = new URLRequest("http://localhost:3000/" + fileFolder + "/" + serverFiles.selectedItem.toString());
	    downloadURL.method = URLRequestMethod.POST;
		
		
	    try {
	        downloadfileRef.download(downloadURL, serverFiles.selectedItem.toString());
	        
	    } catch (error:Error) {
	        trace("Unable to download file. " + error);
	    }
	}
	
				
	private function downloadProgressHandler(event:ProgressEvent):void
	{		pb.label = "Downloading " + event.currentTarget.name + " " + Math.floor((event.bytesLoaded/event.bytesTotal)*100) + "% complete";
		pb.setProgress(event.bytesLoaded, event.bytesTotal);
	}

	private function downloadIOHandler(event:Event):void
	{
		trace ("Download failed: " + event);
	}
	
	private function downloadCompleteHandler(event:Event):void
	{
		downloadfileRef.removeEventListener(Event.COMPLETE, downloadCompleteHandler);
		downloadfileRef.removeEventListener(ProgressEvent.PROGRESS, downloadProgressHandler);
		downloadfileRef.removeEventListener(IOErrorEvent.IO_ERROR, downloadIOHandler);
		pb.label = "LOADING 0%";;
		pb.setProgress(0, 0);
	}